package com.winit.cloudlink.mgmt.rabbit;

import com.winit.cloudlink.common.URL;

import static org.apache.commons.lang3.StringUtils.isNotBlank;

public class URLUtils {
    public static boolean isSameAddress(URL sourceURL, URL destinationURL) {
        if (!sourceURL.getHost().equals(destinationURL.getHost())) {
            return false;
        }

        if (sourceURL.getPort() != destinationURL.getPort()) {
            return false;
        }

        String sourceVirtualHost = isNotBlank(sourceURL.getPath()) ? sourceURL.getPath() : "/";
        String destinationVirtualHost = isNotBlank(destinationURL.getPath()) ? destinationURL.getPath() : "/";
        if (!sourceVirtualHost.equals(destinationVirtualHost)) {
            return false;
        }
        return true;
    }
}
